package com.example.demo.smartLamp.controller;

import com.example.demo.common.ApiResponse;
import com.example.demo.smartLamp.service.UploadService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author cc
 * 视频图片上传接口
 */
@Api(value = "视频图片",tags = "视频图片")
@RestController
@RequestMapping("/upload")
public class UploadController {

    @Autowired
    private UploadService uploadService;

    /**
     * 视频文件上传
     * @param request
     * @return
     * @throws Exception
     */
    @ApiOperation("视频文件上传")
    @RequestMapping(value ="/uploadVideo",method= RequestMethod.POST)
    public ApiResponse uploadVideo(@RequestParam(value = "file") MultipartFile file, @RequestParam(value = "title")String title, HttpServletRequest request) throws Exception{
        return uploadService.uploadVideo(file, title, request);
    }

    /**
     * 图片文件上传
     * @param request
     * @return
     * @throws Exception
     */
    @ApiOperation("图片上传")
    @RequestMapping(value ="/uploadImage",method=RequestMethod.POST)
    public ApiResponse uploadImage(@RequestParam(value = "file") MultipartFile file,@RequestParam(value = "title")String title, HttpServletRequest request) throws Exception{
        return uploadService.uploadImage(file, title, request);
    }

    /**
     * 获取视频和图片信息
     * @return
     */
    @ApiOperation(value="获取视频和图片信息")
    @PostMapping("/getAllVideoAndImage")
    public ApiResponse getAllVideoAndImage(){
        return uploadService.getAllVideoAndImage();
    }


}
